import 'dart:math';

import 'package:dartx/dartx.dart';
import 'package:get/get.dart';
import 'package:sgy_flutter/extensions/get.dart';

class AdjustZeroRecordLogic extends GetxController {

  RxList<Pair<Pair<int, String>?, Pair<int, String>?>> items = RxList.empty(growable: true);

  @override
  void onReady() async{
    if (bleManager.deviceModel?.isDoubleSlide == true || rightBleManager.deviceModel?.isDoubleSlide == true){
      List<Pair<int, String>>? left;
      try{
        left = await bleManager.fetchAdjustZeroRecord();
      }catch(e){

      }
      List<Pair<int, String>>? right;
      try{
        right = await rightBleManager.fetchAdjustZeroRecord();
      }catch(e){

      }

      for (var i = 0; i < min(left?.length?? 1000, right?.length??1000); i ++) {
        final lp = left?[i];
        final rp = right?[i];
        items.add(Pair(lp, rp));
      }

    }else{
      if (await bleManager.ensureDeviceConnected()) {
        final left = await bleManager.fetchAdjustZeroRecord();
        for (var item in left) {
          items.add(Pair(item, null));
        }

      }
    }

    super.onReady();
  }

}
